package topopt;

import fem2.AbstractStructuralStaticDemo;
import fem2.Constraint;
import fem2.Force;
import fem2.Mesh;
import fem2.MeshGenerator;
import fem2.MeshUtilities;
import fem2.Model;
import fem2.Node;
import fem2.material.TopOptFilter;
import fem2.material.TopOptSensitivityFilter;
import fem2.pre_and_post.GidMeshGenerator;

public class MBBbeamTriMeshTopOptDemo extends AbstractTopOptDemo {

	public MBBbeamTriMeshTopOptDemo() {
		projectName = "topopt-tri.gid";
		meshFileName = "mesh1.msh";
	}

	@Override
	public Mesh createMesh() {
		String fn = projectDir + '/' + projectName + '/' + meshFileName;
		MeshGenerator mg = new GidMeshGenerator(fn);
		return mg.getMesh(2);
	}

	@Override
	public TopOptFilter createFilter(Model m) {
		double rmin = 1.5;
		TopOptFilter filter = new TopOptSensitivityFilter(m, rmin);
		return filter;
	}

	@Override
	public Model createConditions(Model m) {
		Mesh mesh = m.getMesh();
		Constraint c1 = new Constraint(false, true);
		Constraint c2 = new Constraint(true, false);
		mesh.setConstraint(c1, MeshUtilities.seekNodesOnSurface(mesh, 1.0, 0.0, 0.0));
		MeshUtilities.seekNode(mesh, 60.0, 0.0).setConstraint(c2);

		Node nf = MeshUtilities.seekNode(mesh, 0.0, 20.0);
		double F = -1.0;
		Force f = new Force(nf, 0, F);
		m.addLoad(f);
		return m;
	}

	public static void main(String[] args) {
		AbstractStructuralStaticDemo demo = new MBBbeamTriMeshTopOptDemo();

		demo.run();
	}
}
